package advance.x000.acw_94;


import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;


public class Main {
    public static int[] nums;
    public static boolean[] chosen;
    public static int[] subset;

    //递归实现排列型枚举
    public static void main(String[] args) {
        Main solution = new Main();
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        chosen = new boolean[n];
        nums = new int[n];
        subset = new int[n];
        for (int i = 0; i < n; i++) {
            nums[i] = i + 1;
        }
        solution.clac(0);
    }

    private void clac(int cur) {
        if (cur == nums.length) {
            print(subset);
            return;
        }

        for (int i = 0; i < nums.length; i++) {
            if (chosen[i]) continue;

            chosen[i] = true;
            subset[cur] = nums[i];
            clac(cur + 1);
            chosen[i] = false;
            subset[cur] = 0;
        }

    }

    public void print(int[] nums) {
        for (int i = 0; i < nums.length; i++) {
            System.out.print(nums[i] + " ");
        }
        System.out.println();
    }

}
